package com.wujie.activies.service.imp;

import com.wujie.activies.dao.ContactMapper;
import com.wujie.activies.model.Contact;
import com.wujie.activies.model.ContactExample;
import com.wujie.activies.service.IContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 晒太阳的鱼 on 2015/12/6.
 */
@Service("contactService")
public class ContactServiceImpl implements IContactService {

    @Autowired
    private ContactMapper contactMapper;

    @Override
    public int deleteByPrimaryKey(Integer key) {
        return contactMapper.deleteByPrimaryKey(key);
    }

    @Override
    public Contact getByPrimaryKey(Integer key) {
        return contactMapper.selectByPrimaryKey(key);
    }

    @Override
    public List<Contact> getByInstance(Contact ele) {
        ContactExample ce = new ContactExample();
        ce.createCriteria().andNameEqualTo(ele.getName())
            .andAgeEqualTo(ele.getAge()).andSexEqualTo(ele.getSex()).andSchoolEqualTo(ele.getSchool());
        return contactMapper.selectByExample(ce);
    }

    @Override
    public int insertSelective(Contact record) {
        return contactMapper.insertSelective(record);
    }


    @Override
    public int updateByPrimaryKey(Contact record)
    {
        return contactMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<Contact> getAll() {
        ContactExample contactExample = new ContactExample();
        return contactMapper.selectByExample(contactExample);
    }

}
